﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
@* 羊只转舍显示页面 *@
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">转舍日期</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <input type="date" id="sheepTransferTime" class="layui-input">
                    </div>
                    <label class="layui-form-label">羊只耳号</label>
                    <div class="layui-input-inline layui-input-wrap">
                        <select id="earBugles">
                        <option value="">请选择</option>
                        </select>
                    </div>
                    @* <div class="layui-inline">
                        <label class="layui-form-label">转舍类型</label>
                        <div class="layui-input-block">
                            <select id="persId" lay-filter="testSelect">
                                <option value="">请选择</option>
                                <option value="种母配种转舍">种母配种转舍</option>
                                <option value="种母妊检转舍">种母妊检转舍</option>
                                <option value="种母分娩转舍">种母分娩转舍</option>
                                <option value="种母产羔转舍">种母产羔转舍</option>
                                <option value="种母断奶转舍">种母断奶转舍</option>
                                <option value="后备转种转舍">后备转种转舍</option>
                                <option value="羊只期初转舍">羊只期初转舍</option>
                                <option value="羊只采购转舍">羊只采购转舍</option>
                                <option value="公羊调教转舍">公羊调教转舍</option>
                                <option value="羔羊断奶转舍">羔羊断奶转舍</option>
                                <option value="产羔断奶转舍">产羔断奶转舍</option>
                                <option value="后裔转种转舍">后裔转种转舍</option>
                                <option value="羊只转舍">羊只转舍</option>
                                <option value="羊只戴表转舍">羊只戴表转舍</option>
                            </select>
                        </div>
                    </div> *@

                    <div class="layui-inline">
                        <label class="layui-form-label">转出栋舍</label>
                        <div class="layui-input-block">
                            <select id="rollOutBuildings" lay-filter="testSelect1">
                                <option value="">请选择</option>
                                <option value="大羊舍">大羊舍</option>
                                <option value="配种舍">配种舍</option>
                                <option value="采购羊栋舍">采购羊栋舍</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">转出栏位</label>
                        <div class="layui-input-block">
                            <select id="rollOutColumns" lay-filter="testSelect2">
                                <option value="">请选择</option>
                                <option value="大羊舍">大羊舍</option>
                                <option value="配种舍">配种舍</option>
                                <option value="采购羊栋舍">采购羊栋舍</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">转入栋舍</label>
                        <div class="layui-input-block">
                            <select id="intoBuildings" lay-filter="testSelect3">
                                <option value="">请选择</option>
                                <option value="大羊舍">大羊舍</option>
                                <option value="配种舍">配种舍</option>
                                <option value="采购羊栋舍">采购羊栋舍</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">转入栏位</label>
                        <div class="layui-input-block">
                            <select id="intoColumns" lay-filter="testSelect4">
                                <option value="">请选择</option>
                                <option value="大羊舍">大羊舍</option>
                                <option value="配种舍">配种舍</option>
                                <option value="采购羊栋舍">采购羊栋舍</option>
                            </select>
                        </div>
                    </div>

                </div>
                <button type="button" class="layui-btn layui-bg-red" id="searchBtn" onclick="Show()">搜索</button>

                <button type="button" class="layui-btn layui-bg-red" onclick="location.href='/Birth/AddSheepTransfer'">新增</button>

            </div>


        </div>


        <table class="layui-table">
            <thead>
                <tr>
                    <td>序号</td>
                    <td>转舍日期</td>
                    <td>羊只耳号</td>
                    @* <td>转舍类型</td> *@
                    <td>转出栋舍</td>
                    <td>转出栏位</td>
                    <td>品种</td>
                    <td>性别</td>
                    <td>创建人</td>
                    <td>创建时间</td>
                    <td>修改时间</td>
                    <td>修改人</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
        <div id="demo-laypage-all"></div>

    </form>


    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>
    <script>
        layui.use(function () {
            var laypage = layui.laypage;
            var pageIndex = 1;
            var pageSize = 5;



            var $ = layui.$;
            var layer = layui.layer;
            var util = layui.util;
            Show();

            // 事件
            util.on('lay-on', {

                'test-iframe-curl': function () {
                    layer.open({
                        type: 2,
                        title: '羊只转舍-新增',
                        shadeClose: true,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['900px', '600px'],
                        content: ''
                    });
                }

            })

            var form = layui.form;
            var $ = layui.jquery;

            $(function () {
                bangsheng();
            })
            function bangsheng() {

                $.ajax({
                    url: "http://localhost:5269/api/SheepArchive/SheepEarBuglesQuery",
                    data: JSON.stringify({}),
                    type: "post",
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        $.each(res.data, function () {
                            $("#earBugles").append(`<option value="${this.recordAuricle}">${this.recordAuricle}</option>`);
                        })
                        form.render('select'); // 重新渲染下拉框

                    }

                })
            }

           
            $('#searchBtn').click(function () {
                var keyword = $('#sheepTransferTime').val(); // 获取文本框的输入内容
                Show()
            });
            $('#searchBtn').click(function () {
                var keyword1 = $('#earBugles').val(); // 获取文本框的输入内容
                Show()
            });


            


            //显示列表
            function Show() {
                var sheepTransferTime = null;
                var earBugles = $("#earBugles").val()
                var rollOutBuildings = $("#rollOutBuildings").val()
                var rollOutColumns = $("#rollOutColumns").val()
                var intoBuildings = $("#intoBuildings").val()
                var intoColumns = $("#intoColumns").val()
                $.post({
                    url: 'http://localhost:5269/api/SheepArchive/SheepTransferQuery',
                    data: JSON.stringify
                    ({ sheepTransferTime: sheepTransferTime, earBugles: earBugles,rollOutBuildings:rollOutBuildings,rollOutColumns:rollOutColumns,intoBuildings:intoBuildings,intoColumns:intoColumns,pageIndex: pageIndex, pageSize: pageSize 
                    }),
                    async: false,
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        var count = "";
                        $.each(res.data, function () {
                            if (this.createdOwnerId==null){
                                this.createdOwnerId=""
                            }
                            if (this.createdTime == null) {
                                this.createdTime = ""
                            }
                             else{
                                this.createdTime = moment(this.createdTime).format("YYYY-MM-DD HH:mm:ss")
                            }
                            if (this.updatedOwnerId == null) {
                                this.updatedOwnerId = ""
                            }
                            if (this.updatedTime == null) {
                                this.updatedTime = ""
                            }
                            else{
                                this.sheepTransferTime = moment(this.sheepTransferTime).format("YYYY-MM-DD HH:mm:ss")
                            }
                            count += `
                                 <tr>
                                      <td>${this.sheepTransferId}</td>
                                      <td>${this.sheepTransferTime}</td>
                                      <td>${this.earBugles}</td>
                                      @*<td>${this.transferType}</td>*@
                                      <td>${this.rollOutBuildings}</td>
                                      <td>${this.rollOutColumns}</td>
                                      <td>${this.variety}</td>
                                      <td>${this.sex}</td>
                                      <td>${this.createdOwnerId}</td>
                                      <td>${this.createdTime}</td>
                                      <td>${this.updatedOwnerId}</td>
                                      <td>${this.updatedTime}</td>

                                     <td>
                                     <a onclick="funDel()" class="btn btn-link">删除</a>
                                      <a onclick="funDel()" class="btn btn-link" lay-on="test-iframe-curl">编辑</a>
                                     </td>
                                 </tr>
                        `
                        })
                        console.log(count)
                        console.log(res.data)
                        //pagedCount = res.pagedCount;
                        //pcount = res.totalCount;
                        $("tbody").html(count)
                        // console.log(res.data)

                        //var page = Math.ceil(res.totalCount / 5);  //总页数
                        console.log(996, pageSize, pageIndex, res);
                        // 完整显示
                        laypage.render({
                            elem: 'demo-laypage-all', // 元素 id
                            curr: pageIndex,//当前页
                            pages: res.pagedCount,    //总页数
                            limit: pageSize,//每页几条
                            limits: [5, 10, 15],
                            count: res.totalCount, // 数据总数
                            layout: ['count', 'prev', 'page', 'first', 'last', 'next', 'limit', 'skip'], // 功能布局
                            jump: function (obj, first) {
                                if (!first) {
                                    console.log(888, obj);
                                    console.log(obj.curr); // 得到当前页，以便向服务端请求对应页的数据。
                                    console.log(obj.limit); // 得到每页显示的条数
                                    pageIndex = obj.curr;
                                    pageSize = obj.limit;
                                    Show();
                                }
                            }
                        });
                    }
                })


            }

        });


    </script>


</body>

</html>